package org.xiaov.lunasql.spring.mybatis;

import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.dromara.hutool.log.LogUtil;
import org.xiaov.lunasql.engine.common.util.LunaJdbcUtils;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Properties;

/**
 * <p>
 * LunaDatabaseIdProvider
 * </p>
 *
 * @author lzq
 * @since 2024/12/25 16:23
 */
public class LunaDatabaseIdProvider implements DatabaseIdProvider {
    @Override
    public void setProperties(Properties p) {
        DatabaseIdProvider.super.setProperties(p);
    }

    @Override
    public String getDatabaseId(DataSource dataSource) throws SQLException {
        String url = dataSource.getConnection().getMetaData().getURL();
        String dbType = LunaJdbcUtils.getDbType(url);
        LogUtil.info("当前数据库类型为：{}", dbType);
        return dbType;
    }
}
